package com.test.pudamoney.activity_fragment_pudamoney;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.test.pudamoney.R;
import com.test.pudamoney.activity_fragment_pudamoney.base_pudamoney.BaseActivity_pudamoney;
import com.test.pudamoney.util_pudamoney.ThreadUtil_pudamoney;
import com.test.pudamoney.util_pudamoney.http_pudamoney.HttpManager_pudamoney;
import com.test.pudamoney.view_pudamoney.widget_pudamoney.TitleView_pudamoney;

import java.util.ArrayList;

public class ServiceFeedbackActivity_pudamoney extends BaseActivity_pudamoney {

    private String type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service_feedback_pudamoney);
        init();
    }

    private void init(){

        TitleView_pudamoney titleView = findViewById(R.id.activity_service_feedback_view_title);
        setBackBtn_pudamoney(titleView.getBackIb());

        ArrayList<TextView> typeTvs = new ArrayList<TextView>(){{
            add(findViewById(R.id.activity_service_feedback_tv_product_suggestion));
            add(findViewById(R.id.activity_service_feedback_tv_app_bugs));
            add(findViewById(R.id.activity_service_feedback_tv_payment_issues));
            add(findViewById(R.id.activity_service_feedback_tv_others));
        }};

        for (TextView typeTv1:typeTvs){
            typeTv1.setOnClickListener(v -> {
                for (TextView typeTv2:typeTvs){
                    if (typeTv1==typeTv2){
                        typeTv2.setBackgroundResource(R.drawable.ic_bg_service_feedback_check);
                        typeTv2.setTextColor(getColor(R.color.black));
                        type = typeTv2.getText().toString();
                    }else {
                        typeTv2.setBackgroundResource(R.drawable.ic_rc_gray_lll_12dp);
                        typeTv2.setTextColor(getColor(R.color.gray_ddd));
                    }
                }
            });
        }

        EditText inputEt = findViewById(R.id.activity_service_feedback_et_input);
        Button submitBtn = findViewById(R.id.activity_service_feedback_btn_submit);

        submitBtn.setOnClickListener(v -> {
            String input = inputEt.getText().toString();
            if (TextUtils.isEmpty(type)||TextUtils.isEmpty(input)) {
                showToast_pudamoney(getString(R.string.word_input_tip));
                return;
            }
            HttpManager_pudamoney.getInstance().submitServiceFeedback(type,input);
        });

    }

    public void onSubmitServiceFeedback(){
        showToast_pudamoney(getString(R.string.word_submit_success));
        ThreadUtil_pudamoney.getInstance().postDelay(this::onBackPressed,1000);
    }

}